<template>
	<div class="basic-info">

		<el-form :inline="true" :model="basicInfoData" :rules="rules" label-width="90px" ref="basicInfoData">
			<!--{{basicInfoData.status}}待检测时耶不可用-->
			<el-form-item label="名称" prop="name">
				<el-input clearable v-model="basicInfoData.name" size="mini" placeholder="名称" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502"></el-input>
			</el-form-item>
			<el-form-item label="类型" prop="taskType">
				<el-select style="width:100%;" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502" clearable @change='typeSelect' v-model="basicInfoData.taskType"
				 placeholder="请选择" size="mini">
					<el-option v-for="item in reportWordList.itemList" :key="item.code" :label="item.name" :value="item.code">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="客户" prop="client">
				<el-select style="width:100%;" disabled clearable filterable v-model="basicInfoData.client"
				 @change="clientSelect" placeholder="请选择" size="mini">
					<el-option v-for="item in inspectionUnitTableDate2" :key="item.id" :label="item.name" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="是否盲码" prop="doBlind">
				<el-select   style="width:100%;" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502" clearable v-model="basicInfoData.doBlind" placeholder="请选择" size="mini">
					<el-option :key="true" :value="true" label="是"></el-option>
					<el-option :key="false" :value="false" label="否"></el-option>
				</el-select>
			</el-form-item>
			<!--<el-form-item label="编号" prop="code">
				<el-input size="mini" placeholder="" v-model="basicInfoData.code" disabled placeholder="后台生成"></el-input>
			</el-form-item>-->
			<el-form-item label="采样来源" prop="source">
				<el-select  style="width:100%;" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502" clearable v-model="basicInfoData.source" placeholder="请选择" size="mini">
					<el-option v-for="item in sampleSourceData" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
      <el-form-item :label="stationName" prop="offices">
        <el-select v-model="basicInfoData.offices" placeholder="请选择" size="mini" style="width:100%" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502">
          <el-option label="全部" value="ALL"></el-option>
          <el-option v-for="item in stationList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
			<el-form-item label="采样日期" prop="collectionDate" v-if="['添加模板','编辑模板','查看模板','模板审核'].indexOf(title)<0 && basicInfoData.source == 0">
				<el-date-picker  :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502" clearable v-model="basicInfoData.collectionDate" type="date"
				 size="mini" placeholder="选择日期" value-format='yyyy-MM-dd' style="width: 100%;">
				</el-date-picker>
			</el-form-item>
      <!-- {{title}} -->
      <!-- v-if="['添加模板','编辑模板','查看模板','模板审核'].indexOf(title)<0" -->
			<el-form-item label="加测码" prop="uniqueCode" >
			  <el-input  v-model="basicInfoData.uniqueCode" size="mini" placeholder="加测码" style="width:100%" :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502"></el-input>
			</el-form-item>
			<el-form-item label="驳回意见" prop="remark" v-if="basicInfoData.remark && getPlanData.status == 502">
				<el-input :disabled="['查看模板','模板审核','任务详情','任务签发'].indexOf(title)>-1 || getPlanData.status == 502" type="textarea" :rows="2" size="mini" placeholder="请输入内容" v-model="basicInfoData.remark">
				</el-input>
			</el-form-item>
		</el-form>

		<div v-if="['添加模板','编辑模板','查看模板','模板审核','模板复制'].indexOf(title)>=0">
			<div style="padding: 10px 0;border: 1px solid #eee;">
				<div class="penalrow selectw100">
					<div class="inlineblock verticalmiddle infoitem">
						配置自动循环参数
					</div>
				</div>
				<div class="penalrow selectw100">
					<div class="inlineblock verticalmiddle infoitem">
						<div class="inlineblock verticalmiddle">
							自动下达状态
						</div>
						<div class="inlineblock verticalmiddle informationItem" style="width:calc(100% - 150px);">
							<el-select :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="basicInfoData.doAuto" placeholder="请选择" size="mini">
								<el-option v-for="item in cycStatus" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</div>
					</div>
				</div>
				<div style="padding:10px 10px 10px 20px;width:100%;" v-if="basicInfoData.doAuto==true">
					<div class="inlineblock verticalmiddle startTime">
						<div class="inlineblock verticalmiddle text">
							时
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-select size="mini" :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="hours" placeholder="请选择" clearable multiple
							 @change="hoursChange">
								<el-option v-for="index of 24" :key="index-1" :label="index-1" :value="index-1+''">
								</el-option>
							</el-select>
						</div>
					</div>
					<div class="inlineblock verticalmiddle startTime">
						<div class="inlineblock verticalmiddle text">
							日
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-select size="mini" :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="day" placeholder="请选择" clearable multiple
							 @change="dayChange">
								<el-option v-for="index of getMonthDay" :key="index" :label="index" :value="index+''">
								</el-option>
							</el-select>
						</div>
					</div>
					<div class="inlineblock verticalmiddle startTime">
						<div class="inlineblock verticalmiddle text">
							月
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-select size="mini" :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="month" placeholder="请选择" clearable multiple
							 @change="monthChange">
								<el-option v-for="index of 12" :key="index" :label="index" :value="index+''">
								</el-option>
							</el-select>
						</div>
					</div>
					<div class="inlineblock verticalmiddle startTime">
						<div class="inlineblock verticalmiddle text">
							星期
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-select size="mini" :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="week" placeholder="请选择" clearable multiple
							 @change="weekChange">
								<!--<el-option v-for="index of 7" :key="index" :label="index" :value="index+''">
								</el-option>-->
								<el-option v-for="item in weekOptions" :key="item.value" :label="item.label" :value="item.value+''">
								</el-option>
							</el-select>
						</div>
					</div>
					<div class="inlineblock verticalmiddle startTime">
						<div class="inlineblock verticalmiddle text">
							年
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-select size="mini" :disabled="['查看模板','模板审核'].indexOf(title)>-1" v-model="year" placeholder="请选择" clearable @change="yearChange">
								<el-option v-for="index of 30" :key="index" :label="getYear+index+''" :value="getYear+index+''">
								</el-option>
							</el-select>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

</template>

<script>
	import { mapState } from 'vuex'
	export default {
		props: ['taskDetailShow', 'type', 'canNotEdit', 'showCycleDetail', 'isPlan', 'looksll', 'bidui', 'isBD', 'lookJieGuo', 'bigtype', 'ifnewtask', 'title', 'getPlanData'],
		data() {
			return {
				hours: [],
				day: [],
				month: [],
				week: [],
				year: '',
				inspectionUnitTableDate2Value: '',
				taskTypeTableDateValue: '',
				renwuleixingValue: '',
				sampleSource: '',
				caiyangriqi: '',
				cycStatusValue: '',
				cycleModeValue: '',
				cycDayNum: 1,
				cycTime: '08:00',
				waibuorneibuValue: '001',
				basicInfoData: {
					"collectionDate":null,
					"name": "",
					"code": "",
					"taskType": "",
					"reportWord": "",
					"client": "",
					"doAuto": false,
					"doBlind": false,
					"source": 0,
					"timeExpression": {
						"id": "",
						"businessId": "",
						"hours": "",
						"day": "",
						"month": "",
						"week": "",
						"year": ""
					},
				},
				rules: {
					name: [
						{ required: true, message: '请输入名称', trigger: 'blur' },],
					taskType: [
						{ required: true, message: '选择类型', trigger: 'blur' },],
					client: [
						{ required: true, message: '请选择客户', trigger: 'blur' },],
					doAuto: [
						{ required: true, message: '请选择', trigger: 'blur' },],
					source: [
						{ required: true, message: '请选择采样来源', trigger: 'blur' }
					],
          offices: [
          	{ required: true, message: '请选择', trigger: 'blur' }
          ],
					// collectionDate: [
					// 	{ required: true, message: '请输入日期', trigger: 'change' },],

				},
				renwuleixing: [{
					dictionaryID: '1',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'HJ',
					fieldName: '日检任务',
					status: '1'
				},
				{
					dictionaryID: '2',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'HZ',
					fieldName: '周检任务',
					status: '1'
				},
				{
					dictionaryID: '3',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'CC',
					fieldName: '月检任务',
					status: '1'
				},
				{
					dictionaryID: '4',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'LS',
					fieldName: '临时任务',
					status: '1'
				},
				{
					dictionaryID: '5',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'BD',
					fieldName: '室间比对',
					status: '1'
				},
				{
					dictionaryID: '6',
					dictionaryName: '任务类型',
					dictionaryEName: 'task_type',
					fieldID: 'KH',
					fieldName: '盲样考核',
					status: '1'
				}],
				sampleSourceData: [
					{
						value: 0,
						label: '采样'
					}, {
						value: 1,
						label: '送样'
					}

				],
				weekOptions:[{
						label:'一',
						value:2
					},{
						label:'二',
						value:3
					},{
						label:'三',
						value:4
					},{
						label:'四',
						value:5
					},{
						label:'五',
						value:6
					},{
						label:'六',
						value:7
					},{
						label:'日',
						value:1
					},

				],
        stationName:"厂站",
        stationList:[],
			}
		},
		computed: {
			//			day:{
			//				  get: function () {
			//				      return this.day
			//				    },
			//				    // setter
			//				    set: function (newValue) {
			//				      this.day = newValue
			//				    }
			//			},
			getMonthDay() {
				var date = new Date();
				//将当前月份加1，下移到下一个月
				date.setMonth(date.getMonth() + 1);
				//将当前的日期置为0，
				date.setDate(0);
				//再获取天数即取上个月的最后一天的天数
				var days = date.getDate();
				return days;

			},
			getYear() {
				var date = new Date();
				var year = date.getFullYear() - 1;
				return year;
			},
			...mapState(['inspectionUnitTableDate2', 'waibuorneibu', 'cycStatus', 'cycleMode', 'reportWordList']),
		},
		mounted() {
      this.getStaion();
			this.basicInfoData = this.getPlanData

			if (this.basicInfoData.timeExpression && Object.keys(this.basicInfoData.timeExpression).length != 0) {

				this.hours = this.basicInfoData.timeExpression.hours
				this.day = this.basicInfoData.timeExpression.day
				this.week = this.basicInfoData.timeExpression.week
				this.month = this.basicInfoData.timeExpression.month
				this.year = this.basicInfoData.timeExpression.year
			}
			//			console.log(this.getMonthDay())

		},
		methods: {
      getStaion(){
        this.stationName = this.util.getStationName()
        this.stationList = this.util.getStationList()

      },
			hoursChange(val) {

				this.basicInfoData.timeExpression.hours = this.hours
			},
			dayChange(val) {
				this.basicInfoData.timeExpression.week = this.week = [];
				this.basicInfoData.timeExpression.day = this.day
			},
			weekChange(val) {
				this.basicInfoData.timeExpression.day = this.day = []
				this.basicInfoData.timeExpression.week = this.week
			},
			monthChange(Val) {
				this.basicInfoData.timeExpression.month = this.month
			},
			yearChange(val) {
				this.basicInfoData.timeExpression.year = this.year
			},
			typeSelect(val) {
				this.basicInfoData.reportWord = val
				//				for(let i of this.reportWordList.itemList){
				//					if(i.id == val){
				//						this.basicInfoData.reportWord = i.code
				//					}
				//				}
			},
			//			通过客户id获取检测区域信息
			clientSelect(val) {

				this.$store.dispatch('getMonitorZones', val)
			}
		},
		watch: {
			taskTypeTableDateValue: function (val) {
				if (val == 'BD') {
					this.waibuorneibuValue = '001'
				}
			},
			title() {
				console.log(this.title)

			}
		},
	}

</script>

<style>
	.basic-info {
		margin-top:25px;
	}
	.basic-info .el-form-item {
		margin-bottom: 15px;
		width: 31%;
	}

	.basic-info .el-form-item__content {
		width: calc(100% - 90px)
	}

	.basic-info .informationItem {
		width: calc(100% - 45px);
	}
	.inlineblock.verticalmiddle.startTime{
		width: 100%;
		display: block;
		margin-bottom: 10px;
	}
	.inlineblock.verticalmiddle.startTime .text{
		width:25px;
	}
	.inlineblock.verticalmiddle.startTime .informationItem{
		width:calc(100% - 45px)
	}

	.inlineblock.verticalmiddle.startTime .el-select{
		width:100%;
	}
</style>
